package com.train.common.enums.impl;

import cn.hutool.core.util.ArrayUtil;
import com.train.common.enums.Enums;

/**
 * 业务异常枚举
 */
public enum BizExceptionEnums implements Enums {

    EXP_EXISTS_REGISTER_USER(100012, "注册失败，账号已存在"),
    EXP_BAD_REGISTER_USER(100013, "注册失败,请联系系统管理人员"),
    EXP_EXPIRE_CAPTCHA(100014, "图形验证码已过期"),
    EXP_SAVE_SMS_RECORD(100015, "短信记录保存失败"),
    EXP_FREQUENT_SEND_SMS(100016, "发送短信频繁, 请稍后再试"),
    EXP_ERROR_CAPTCHA(100017, "图形验证码错误"),
    EXP_SEND_SMS_FAIL(100018, "发送短信失败"),
    EXP_MEMBER_NOT_EXISTS(100019, "该用户不存在"),
    EXP_EXPIRE_SMS_CODE(100020, "短信验证码过期"),
    EXP_EDIT_SMS_RECORD(100021, "短信记录更新失败"),
    EXP_ERROR_SMS_CODE(100022, "短信验证码错误"),
    EXP_ADD_PASSENGER(100023, "添加乘车人失败"),
    EXP_PASSENGER_TYPE(100024, "无效类型"),
    EXP_MEMBER_ID_UNIQUE(100025, "该会员已存在"),
    EXP_PASSENGER_EXISTS(100026, "已经存在该乘车人, 请勿重复添加"),
    EXP_PASSENGER_NOT_EXISTS(100027, "更新失败,该乘客不存在"),
    EXP_REMOVE_PASSENGER(100028, "删除乘车人失败"),
    EXP_STATION_NOT_EXISTS(100029, "车站不存在"),
    EXP_ADD_STATION(100030, "添加车站失败"),
    EXP_REMOVE_STATION(100031, "删除车站失败"),
    EXP_TRAIN_NOT_EXISTS(100032, "该车次不存在"),
    EXP_ADD_TRAIN(100033, "添加车次失败"),
    EXP_REMOVE_TRAIN(100034, "删除车次失败"),
    EXP_TRAIN_CODE_EXISTS(100035, "车次编号已存在"),
    EXP_TRAIN_TYPE(100036, "车次类型不存在"),
    EXP_TRAIN_TIME(100037, "出发时间必须大于到站时间"),
    EXP_TRAIN_STATION_NOT_EXISTS(100038, "该车次途径站不存在"),
    EXP_ADD_TRAIN_STATION(100039, "添加车次途径站失败"),
    EXP_REMOVE_TRAIN_STATION(100040, "删除车次到达站失败"),
    EXP_TRAIN_CARRIAGE_NOT_EXISTS(100041, "该车次车厢不存在"),
    EXP_ADD_TRAIN_CARRIAGE(100042, "添加火车车厢失败"),
    EXP_REMOVE_TRAIN_CARRIAGE(100043, "删除火车车厢失败"),
    EXP_TRAIN_SEAT_NOT_EXISTS(100044, "该列车座位不存在"),
    EXP_ADD_TRAIN_SEAT(100045, "添加列车座位失败"),
    EXP_REMOVE_TRAIN_SEAT(100046, "删除列车座位失败"),
    EXP_TRAIN_SEAT_GENERATE(100047, "自动生成车厢座位失败"),
    EXP_BATCH_ADD_TRAIN_SEAT(100048, "批量添加列车座位失败"),
    EXP_TRAIN_CARRIAGE_EXISTS(100049, "同车次车厢已存在"),
    EXP_TRAIN_STATION_EXISTS(100050, "同车次站名或站序已存在"),
    EXP_STATION_EXISTS(100051, "该车站已存在"),
    EXP_JOB_NAME_EMPTY(100052, "无效定时任务名"),
    EXP_JOB_RETRY(100053, "定时任务重试失败"),
    EXP_ADD_JOB(100054, "定时任务创建失败"),
    EXP_DELETE_JOB(100055, "定时任务删除失败"),
    EXP_PAUSE_JOB(100056, "定时任务暂停失败"),
    EXP_RESUME_JOB(100057, "定时任务恢复失败"),
    EXP_RUN_JOB(100058, "定时任务启动失败"),
    EXP_UPDATE_JOB(100059, "定时任务更新失败"),
    EXP_NOT_EXISTS_JOB(100060, "该任务不存在"),
    EXP_EXISTS_JOB(100061, "该任务已存在"),
    EXP_SAVE_JOB(100062, "同步定时任务添加失败"),
    EXP_EDIT_JOB(100063, "同步定时任务更新失败"),
    EXP_DAILY_TRAIN_NOT_EXISTS(100064, "该日车次不存在"),
    EXP_ADD_DAILY_TRAIN(100065, "该日车次添加失败"),
    EXP_REMOVE_DAILY_TRAIN(100066, "该日车次删除失败"),
    EXP_DAILY_TRAIN_CODE_EXISTS(100067, "该日车次已存在"),
    EXP_DAILY_TRAIN_STATION_NOT_EXISTS(100068, "该日车次途径车站不存在"),
    EXP_ADD_DAILY_TRAIN_STATION(100069, "该日车次途径车站添加失败"),
    EXP_REMOVE_DAILY_TRAIN_STATION(100070, "该日车次途径车站删除失败"),
    EXP_DAILY_TRAIN_STATION_EXISTS(100071, "该日同车次车站名或站序已存在"),
    EXP_DAILY_TRAIN_CARRIAGE_NOT_EXISTS(100072, "该日车次车厢不存在"),
    EXP_ADD_DAILY_TRAIN_CARRIAGE(100073, "该日车次车厢添加失败"),
    EXP_REMOVE_DAILY_TRAIN_CARRIAGE(100074, "该日车次车厢删除失败"),
    EXP_DAILY_TRAIN_CARRIAGE_EXISTS(100075, "该日车次车厢已存在"),
    EXP_REMOVE_DAILY_TRAIN_SEAT(100078, "该日车次座位删除失败"),
    EXP_DAILY_TRAIN_GENERATE(100079, "每日车次自动生成失败"),
    EXP_DAILY_TRAIN_STATION_GENERATE(100080, "每日途径车站自动生成失败"),
    EXP_DAILY_TRAIN_CARRIAGE_GENERATE(100081, "每日车厢自动生成失败"),
    EXP_DAILY_TRAIN_SEAT_GENERATE(100082, "每日座位自动生成失败"),
    EXP_ADD_DAILY_TRAIN_SEAT(100083, "该日车次座位添加失败"),
    EXP_DAILY_TRAIN_TICKET_NOT_EXISTS(100084, "该日车次车票不存在"),
    EXP_ADD_DAILY_TRAIN_TICKET(100085, "该日车次车票添加失败"),
    EXP_REMOVE_DAILY_TRAIN_TICKET(100086, "该日车次车票删除失败"),
    EXP_TRAIN_CODE_NOT_EXISTS(100087, "该车次编号不存在"),
    EXP_TRAIN_ORDER_TICKET_OVER_LIMIT(100088, "购票数量不能超过5张"),
    EXP_DAILY_TRAIN_START_TIME_ERROR(100089, "该车次已过期"),
    EXP_TRAIN_ORDER_SAVE_FAIL(100090, "订单保存失败"),
    EXP_TRAIN_ORDER_TICKET_NOT_ENOUGH(100091, "余票不足"),
    EXP_TRAIN_ORDER_TICKET_DIFF_SEAT_TYPE(100092, "不允许不同座位类型"),
    EXP_EDIT_DAILY_TRAIN_TICKET(100093, "该日车次车票更新失败"),
    EXP_REDUCE_DAILY_TRAIN_TICKET(100094, "该日车次车票扣减失败"),
    EXP_ADD_TICKET(100095, "车票添加失败"),
    EXP_REMOVE_TICKET(100096, "车票删除失败"),
    EXP_TRAIN_ORDER_UPDATE_FAIL(100097, "订单更新失败"),
    EXP_TRAIN_ORDER_EXISTS(100098, "已存在该车次订单,请勿重复购买"),
    EXP_CONFIRM_ORDER_LOCK(100099, "订单确认失败,请稍后再试"),
    EXP_CONFIRM_ORDER_BLOCK(100100, "抢票人数过多,请稍后再试"),
    EXP_PAY_ORDER_BLOCK(100101, "抢票人数过多,请稍后再试"),
    EXP_DAILY_TRAIN_SK_TOKEN_NOT_EXISTS(100102, "该日车次令牌不存在"),
    EXP_ADD_DAILY_TRAIN_SK_TOKEN(100103, "该日车次令牌添加失败"),
    EXP_REMOVE_DAILY_TRAIN_SK_TOKEN(100104, "该日车次令牌删除失败"),
    EXP_EDIT_DAILY_TRAIN_SK_TOKEN(100105, "该日车次令牌更新失败"),
    EXP_DAILY_TRAIN_SK_TOKEN_ZERO(100106, "该日车次{}已售尽"),
    EXP_CONFIRM_ORDER_TICKET_SCALPING(100107, "抢票人数过多, 请稍后再试"),
    EXP_CONFIRM_ORDER_WAIT_TIMEOUT(100108, "抢票人数过多, 请稍后再试"),
    EXP_CONFIRM_ORDER_CAPTCHA_CODE_EXPIRED(100109,  "验证码已过期"),
    EXP_CONFIRM_ORDER_NOT_EXIST(100110, "订单不存在"),
    EXP_CONFIRM_ORDER_EXIST(100111, "订单已存在"),
    EXP_EDIT_CONFIRM_ORDER_STATUS(100112, "订单状态更新失败"),
    EXP_QUERY_CONFIRM_ORDER_NOT_EXIST(100113, "该订单不存在"),
    EXP_CANCEL_CONFIRM_ORDER_STATUS(100114, "订单取消失败"),
    EXP_PAGE_DAILY_TRAIN_TICKET(100115, "系统繁忙,请稍后再试"),
    EXP_NOT_ALLOW_ADD_DAILY_TRAIN_TICKET(100116, "不允许添加该日车次的车票, 日期:{}, 车次:{}");

    private final Integer code;

    private final String message;

    BizExceptionEnums(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }


    public static BizExceptionEnums getByCode(Integer code) {
        return ArrayUtil.firstMatch(item -> item.getCode().equals(code), values());
    }
}
